﻿using AutoMapper;
using KuaFu.CardIssuing.OpenApi.Args.CardProduct;
using KuaFu.CardIssuing.OpenApi.Model.CardProduct;
using KuaFu.Extensions;
using KuaFu.Extensions.Base;
using KuaFu.Shared;
using KuaFu.Shared.CardIssuingPlatformService.Services.CardProduct;
using KuaFu.Shared.CommonService.DTOs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KuaFu.CardIssuing.OpenApi.Controllers
{
    [Route("api/card_product")]
    public class CardProductController : BaseApiController
    {
        private readonly IServiceProvider _serviceProvider;
        private readonly IMapper _mapper;
        private readonly UserInfo _userInfo;

        public CardProductController(IServiceProvider serviceProvider, IMapper mapper, UserInfo userInfo)
        {
            _serviceProvider = serviceProvider;
            _mapper = mapper;
            _userInfo = userInfo;
        }

        /// <summary>
        /// 获取卡产品列表
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        [HttpPost("list")]
        public async Task<ApiListResult<Shared.CardIssuingPlatformService.DTOs.CardProduct.CardProductDTO, CardProductDTO>> GetListAsync([FromBody] GetCardProductListArgs args)
        {
            var result = await _serviceProvider.GetRequiredService<GetCardProductListService>().ExecuteAsync(new GetCardProductListArgument(_userInfo.GetMerhcantId(), CustomerType.Merchant));
            return new ApiListResult<Shared.CardIssuingPlatformService.DTOs.CardProduct.CardProductDTO, CardProductDTO>(result, _mapper);
        }

        /// <summary>
        /// 更新卡产品支持消费场景
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        [HttpPost("update_support_senarios")]
        public async Task<ApiResult> UpdateSupportSenariosAsync([FromBody] UpdateCardProductSupportSenariosArgs args)
        {
            var argument = new UpdateCardProductSupportSenariosArgument(_userInfo.GetMerhcantId(), CustomerType.Merchant, args.CardProductId,args.ProductName,args.Description,args.SupportSenarios);
            var result = await _serviceProvider.GetRequiredService<UpdateCardProductSupportSenariosService>().ExecuteAsync(argument);
            return new ApiResult(result);
        }
    }
}
